package com.tanhua.server.service;

import com.tanhua.commons.utils.UserHolder;
import com.tanhua.dubbo.api.SoulApi;
import com.tanhua.model.domain.mysql.Answer;
import com.tanhua.model.domain.mysql.QuestionList;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lxb哦吼吼
 * @version 1.0
 * @description: TODO
 * @date 2021/11/20 21:26
 */

@Service
public class TestSoulService {

    @DubboReference
    private SoulApi soulApi;

//    @Autowired
//    private RedisTemplate redisTemplate;

    @Cacheable(value = "TEST_SOUL", key = "T(com.tanhua.commons.utils.UserHolder).getUserId()")
    public List<QuestionList> getSoulList() {
        Long userId = UserHolder.getUserId();
        List<QuestionList> list = soulApi.getQuestionList(userId);
        //redisTemplate.opsForValue().set(Constants.TEST_SOUL, JSON.toJSONString(list), 30, TimeUnit.MINUTES);
        return list;
    }

    @CacheEvict(value = "TEST_SOUL", key = "T(com.tanhua.commons.utils.UserHolder).getUserId()")
    public String getReportId(String questionId, List<String> optionIdList) {
        Long userId = UserHolder.getUserId();
        return soulApi.getReportId(userId, questionId, optionIdList);
    }

    public Answer getReport(String reportId) {
        return soulApi.getReport(reportId);
    }
}
